package com.baiduspring.dict;

import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 内容来源
 */
public enum ContentSourceEnum {
    Original(1, "原创"),
    translate(2, "翻译"),
    Reprint(3, "转载");

    private Integer index;
    private String value;

    ContentSourceEnum(Integer index, String value) {
        this.index = index;
        this.value = value;
    }

    public static Optional<List<DictVO<Integer, String>>> contentSources() {
        List<DictVO<Integer, String>> dictVOS = Lists.newArrayList();
        Arrays.asList(ContentSourceEnum.values()).forEach(cs -> {
            DictVO<Integer, String> vo = new DictVO<>();
            vo.setIndex(cs.getIndex());
            vo.setValue(cs.getValue());

            dictVOS.add(vo);
        });
        return Optional.ofNullable(dictVOS);
    }

    public static Optional<ContentSourceEnum> getContentSourceByIndex(Integer index) {
        for (ContentSourceEnum contentSource : ContentSourceEnum.values()) {
            if (contentSource.getIndex().equals(index)) return Optional.ofNullable(contentSource);
        }

        return Optional.empty();
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
